package com.lb.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 删除操作
 */

public class Delete {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取程序与数据库的连接对象
        Connection conn = DriverManager.getConnection("jdbc:mysql://120.77.241.104:3306/libo?useSSL=false","root","ROOT_root_1234");
        //3.获取sql语句的执行对象
        Statement statement = conn.createStatement();
        //4.定义sql语句
        String sql = "DELETE FROM emp WHERE ename = '张三'";
        //5.执行我的sql语句
        int count = statement.executeUpdate(sql);
        System.out.println("count::"+count);
        //6.判断结果
        if (count > 0) {
            System.out.println("删除成功！");
        }else {
            System.out.println("删除失败！");
        }
        //7.释放资源
        statement.close();
        conn.close();


    }
}
